/*
 * '('+
'    stamp bigint primary key,'+
'    user_id varchar(50),' +
'    process_result varchar(50),' +
'    process_time bigint,' +
'    arm_area_idx varchar(500),'+
'    mac  macaddr'+
*/

var global_alarm_log = [
    [ Date.now() - 40000, 
      'test_user_A',
      null,
      null,
      '2',
      '112233445566'],
    
    [ Date.now() - 80000, 
      'test_user_A',
      null,
      null,
      '2',
      '112233445566'],
    
    [ Date.now() - 120000, 
      'test_user_A',
      null,
      null,
      '2',
      '112233445566']
]

    


var pgpromise = require( 'pg-promise' )()

const pgConfig = {
    user: 'postgres',
    password: '123456',
    database: 'postgres',                                                                                   
    host: '127.0.0.1',
    port: '5432',
    poolSize: 5,
}   


async function main () { 
    var db = pgpromise( pgConfig );
    try{

        for( let i = 0; i < global_alarm_log.length; i++ ) { 
            var ret = db.query( "INSERT INTO protector_alarm_log( shopid, stamp, user_id, process_result, process_time, arm_area_idx, mac ) SELECT shopid,  $1, $2, $3, $4, $5, $6 FROM protectors WHERE mac = $6", global_alarm_log[i] );
        }
    }
    catch( error ){ 
        console.log( error );
    }

    try{
        var ret = await db.query( "SELECT * FROM protector_alarm_log") ;
        console.log( ret );
    }
    catch( error ) { 
        console.log( error );
    }
}

main();

